$(document).ready(function () {
    dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: appBosch.crud.read,
                dataType: "json"
            },
            update: {
                url: appBosch.crud.update,
                dataType: "json"
            },
            destroy: {
                url: appBosch.crud.destroy,
                dataType: "json"
            },
            parameterMap: function (options, operation) {
                var params = {};
                switch (operation)
                {
                    case 'read':
                        break;
                    case 'update':
                        params = {models: kendo.stringify(options.models)};
                        break;
                    case 'destroy':
                        params = {id: options.models[0].value};
                }
                return params;
            }
        },
        batch: true,
        schema: {
            model: {
                id: "id",
                fields: {
                    area: {
                        editable: false
                    },
                    line: {
                        editable: false
                    },
                    workstation: {
                        editable: false
                    },
                    user: {
                        editable: false
                    },
                    life: {
                        editable: true,
                        type: 'date'
                    }
                }
            }
        }
    });

    $("#grid").kendoGrid({
        resizable: true,
        columnMenu: true,
        scrollable: true,
        filterable: true,
        selectable: true,
        navigatable: true,
        sortable: true,
        dataSource: dataSource,
        columns: [
            {field: "area", title: "Area"},
            {field: "line", title: "Linea"},
            {field: "workstation", title: "Operación"},
            {field: "user", title: "Asociado"},
            {
                field: "life", 
                title: "Vigencia",
                template: "#=kendo.toString(life, 'd')#"
            },
            {command: [
                    {
                        name: "edit",
                        text: {
                            edit: "",
                            update: "",
                            cancel: ""
                        }
                    }]
            }
        ]
    });
});